import router from './router'
import store from './store'
import { Message } from 'element-ui'
const whiteList = ['/login' , '/404' , '/'] // 路由白名单
router.beforeEach((to, from, next) => {
  const isLogin = localStorage.getItem('token')?true:false
  if(isLogin){
    // 已经登录的
    if (to.path == "/login") {
        next('/')
        return
    } else {
       next()
       return
    }
  }else{
    // 未登录
    if (whiteList.indexOf(to.path) !== -1) {
      // 验证前往的页面是否在白名单内 在 下一步\
      next()
      return
    } else {
      //不在白名单 返回登录页
      router.push({path:'/login'})
      return

    }
  }

})
router.afterEach(() => {
  // finish progress bar
  setTimeout(()=>{
    window.scrollTo(0 , 0)
  },300)

})

